﻿using System;
using System.Web.UI;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using SoftwareDiscipline.SharePoint.UserManagement.Data;

namespace SoftwareDiscipline.SharePoint.UserManagement.Layouts.SoftwareDiscipline
{
    public partial class NewRole : LayoutsPageBase
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                AllRolesDataSource allRolesDataSource = new AllRolesDataSource();
                string newRoleName = textRoleName.Text.ToString();
                string status=allRolesDataSource.AddNewRole(newRoleName);
                if (status=="success")
                {
                    Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
                    Context.Response.Flush();
                    Context.Response.End();
                }
                else
                    if (status == "Exist")
                    {
                        this.LabelErrorMessage.Text = this.GetGlobalResourceObject("swusrmgmt", "NewRole_RoleNameExist") as string;
                    }
                    else
                    {
                        this.LabelErrorMessage.Text = this.GetGlobalResourceObject("swusrmgmt", "NewRole_Error") as string;
                    }
               

            }
            catch (Exception ex)
            {
                this.LabelErrorMessage.Text = this.GetGlobalResourceObject("swusrmgmt", "NewRole_Error") as string + ex.Message;
            }
        }

    }
}
